<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <link rel="stylesheet" href="../../lib.layui/css/layui.css"  media="all">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form" action=""  id="example" lay-filter="example">
                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">出库方：</label>
                                <div class="layui-input-inline">
                                    <select name="outOfWarehouse" lay-filter="outOfWarehouse">
                                        <option value="">请选择</option>
                                        <option value="库房">库房</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                    <label class="layui-form-label">接收处：</label>
                                    <div class="layui-input-inline">
                                        <select name="receivingOffice" lay-filter="receivingOffice">
                                            <option value="">请选择</option>
                                            <option value="药房">药房</option>
                                        </select>
                                    </div>
                            </div>
                        </div>

                    <div class="layui-form-item">
                        <!--药品名称-->
                        <div class="layui-inline">
                            <label class="layui-form-label">药品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="drName" id="test2" lay-verify="required" placeholder=""
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <!--数量-->
                        <div class="layui-inline">
                            <label class="layui-form-label">数量</label>
                            <div class="layui-input-inline">
                                <input type="text" name="number" id="test3" lay-verify="required" placeholder=""
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                        <div class="layui-form-item">
                            <!--仓库单位-->
                            <div class="layui-inline">
                                <label class="layui-form-label">仓库单位:</label>
                                <div class="layui-input-inline">
                                    <select name="company" lay-filter="company">
                                        <option value="">请选择</option>
                                        <option value="34">盒</option>
                                        <option value="35">袋</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">备注:</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="remarks" id="test5" lay-verify="required" placeholder=""
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">

                            <div class="layui-inline" style="display: none">
                                <label class="layui-form-label">录入时间</label>
                                <div class="layui-input-inline">
                                    <input type="datetime" name="entryTime"  id="test14" lay-verify="required" placeholder=""
                                           autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>

                            <div class="layui-inline" style="display: none">
                                <label class="layui-form-label">单据号</label>
                                <div class="layui-input-inline">
                                    <input type="datetime" name="documentNo"  id="test15" lay-verify="required" placeholder=""
                                           autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>

                            <div class="layui-inline" style="display: none">
                                <label class="layui-form-label">token</label>
                                <div class="layui-input-inline">
                                    <input type="datetime" name="token"  id="token" lay-verify="required" placeholder=""
                                           autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>

                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline" style="float:right" ;>
                                <td colspan="6" align="right">
                                    <button type="reset" class="layui-btn layui-btn-danger" id="reset">清空</button>
                                    <button type="button" class="layui-btn layui-btn-warm" id="LAY-component-form-getval">添加</button>
                                </td>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script>
    $(document).ready(function(){
        layui.use(['form', 'layedit','layer'], function(){
            var form = layui.form;
            var layer = layui.layer;
            var layedit = layui.layedit;
            //点击添加，发送ajax请求
            layui.$('#LAY-component-form-getval').on('click', function(){
                //生成录入时间
                var date=new Date();
                var year =date.getFullYear();
                var month=date.getMonth()+1;
                var day=date.getDate()+1;
                var entryTime=year+"-"+month+"-"+day;
                // console.log("录入时间："+entryTime)

                // 生成单据号
                var num="CK";
                var documentNo=num+year+month+day;
                for (var i=0;i<6;i++){
                    documentNo+=Math.floor(Math.random()*10);
                }
                // console.log("单据号："+documentNo);
                var token = sessionStorage.getItem("token");
                //将生成的录入时间,单据号 赋值给表单 录入时间,单据号字段
                form.val('example', {
                    "entryTime": entryTime
                    ,"documentNo":documentNo
                    ,"token":token
                });
                //获取表单的值
                var data = form.val('example');
                // alert(JSON.stringify(data));
                $.ajax({
                    url:"/JT90/DrugsExportController/addDrugsExport",
                    data:data,
                    dataType:"json",
                    type:"post",
                    success:function(Data){
                        if(Data.success){
                            layer.msg('添加成功!', {
                                icon: 1,
                                time: 1500,
                                end: function () {
                                    //关闭当前弹窗
                                    xadmin.close();
                                    // 对父窗口进行刷新
                                    xadmin.father_reload();
                                }
                            });
                        }else{
                            alert(data.message);
                        }
                    },
                    error:function(){ alert("程序出错！");}
                });
            })

            //点击清空，清除页面数据
            $("#reset").trigger("click");
        });
    })
</script>


